// miniprogram/pages/file/index.js
Page({
  data: {
    imgurl: ""
  },
  onLoad: function (options) {

    console.log(11111)
    wx.cloud.callFunction({
      name: 'smzdm',
      data: {
        category: 'youxi'
      }
    }).then(res => {
      console.log(res)
    }).catch(err => console.log(err))
  },
  chooseImg: function () {
    const that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        console.log("上传文件的临时路径列表", res.tempFilePaths)
        const filePath = res.tempFilePaths[0] //上传第一张图片
        const cloudPath = `${Date.now()}-${Math.floor(Math.random(0, 1) * 1000)}` + filePath.match(/.[^.]+?$/)[0]


        wx.cloud.uploadFile({
          cloudPath,
          filePath,
          success: res => {
            console.log('上传成功后获得的res：', res)
            that.setData({
              imgurl: res.fileID
            })
          },
          fail: err => {
            console.log(err)
          }
        })
      }
    })
  },

})